package com.wh.controller.storehousemanage;

import com.wh.pojo.OnShelves;
import com.wh.service.storehousemanage.ShelvesService;
import com.wh.vo.PageResult;
import com.wh.vo.QueryInfo;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/shelves/")
public class ShelvesController {

    @Autowired
    private ShelvesService shelvesService;

    @GetMapping("getQuery")
    public SysResult getQuery(QueryInfo queryInfo){
        Map<String,Object> map = shelvesService.getQuery(queryInfo);
        if (map.size()==0){
            return SysResult.notEnough();
        }else {
            return SysResult.success(map);
        }
    }

    @PostMapping("add")
    public SysResult addShelves(@RequestBody OnShelves onShelves){
//        System.out.println(onShelves);
        shelvesService.addShelves(onShelves);
        return SysResult.success();
    }

    @GetMapping("getShelves")
    public SysResult getShelves(PageResult pageResult){
        pageResult = shelvesService.getShelves(pageResult);
        return SysResult.success(pageResult);
    }

    @DeleteMapping("deleteShelves/{id}")
    public SysResult deleteShelves(@PathVariable String id){
        shelvesService.deleteShelves(id);
        return SysResult.success();
    }

    @PutMapping("updataShelves")
    public SysResult updataShelves(@RequestBody OnShelves onShelves) throws Exception {
        System.out.println(onShelves);
        shelvesService.updataShelves(onShelves);
        return SysResult.success();
    }

}
